<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const checkValid = (matrix) => {
      const N = matrix.length;
      for (let i = 0; i < N; ++i) {
        if (new Set(matrix[i]).size < N) {
          return false;
        }
        if (new Set(matrix.map(row => row[i])).size < N) {
          return false
        }
      }
      return true;
    };
    console.log(checkValid([[1, 2, 3], [3, 1, 2], [2, 3, 1]]));
  </script>
</body>

</html>